package fr.ups.jim.isi.tp4;

import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;

public class EllipseItem extends CanvasItem {
	
	Point startPoint, endPoint;

	EllipseItem(PersistentCanvas canvas, Color o, Color f, Point p) {
		super(canvas, o, f);
		startPoint = new Point(p.x, p.y);
		shape = new Ellipse2D.Double(p.x, p.y, 0, 0);
	}

	EllipseItem(EllipseItem originItem) {
		super(originItem.canvas, originItem.outlineColor, originItem.fillColor);
		Ellipse2D.Double e = (Ellipse2D.Double) originItem.shape;		
		shape = new Ellipse2D.Double(e.x, e.y, e.width,e.height);
	}

	public void update(Point p) {
		endPoint = new Point(p.x, p.y);
		((Ellipse2D.Double)shape).setFrameFromDiagonal(startPoint, endPoint);
		canvas.repaint();
	}


	
	public CanvasItem duplicate() {
		CanvasItem newEllipse = new EllipseItem(this);
		newEllipse.move(10, 10);
		canvas.addItem(newEllipse);
		return newEllipse;
	}

	
	public void move(int disX, int disY) {
		((Ellipse2D.Double)shape).x += disX;
		((Ellipse2D.Double)shape).y += disY;
		canvas.repaint();
	}

}
